import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { HouseEntity } from "./house.entity";
console.log(HouseEntity,'HouseEntity');

export interface HouseRo {
    list: HouseEntity[];
    count: number;
}
@Injectable()
export class HouseService {
    constructor( @InjectRepository(HouseEntity)
    private readonly houseRepository: Repository<HouseEntity>,){}
      // 获取所有房子列表
    async findAll(): Promise<HouseRo> {
        const list = await this.houseRepository.find()
        const count = await this.houseRepository.count();
        return { list: list, count: count };
    }
      // 获取部分房子列表
    async find(query: any): Promise<HouseRo> {
        const where = {
            plotId: query.id
        };
        const list = await this.houseRepository.find({
            where
        })
        const count = await this.houseRepository.count({
            where
        });
        return { list: list, count: count };
    }
    async getHouseById(body:any){
        const Ids = body?.Ids
        const list = await this.houseRepository.find()
        console.log(Ids,list,'获取我的关注房屋');
        const resArr = list.filter((item)=>{
            return Ids.includes(item.id) 
        })
        return {
            status:0,
            data:resArr
        }
    }
}
